package com.hibase.core.sequence.controller;


import com.github.pagehelper.PageInfo;
import com.hibase.common.entity.ResponseModel;
import com.hibase.common.util.EntityUtil;
import com.hibase.core.sequence.entity.MdsCodeSequenceRegex;
import com.hibase.core.sequence.entity.vo.*;
import com.hibase.core.sequence.service.MdsCodeSequenceRegexService;
import com.hibase.core.web.annotation.HibasePostRequestMapping;
import com.hibase.core.web.entity.OperationIdEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 流水号通配符规则表 前端控制器
 * </p>
 *
 * @author chenfeng
 * @since 2021-01-19
 */
@RestController
@RequestMapping("/mds-code-sequence-regex")
@Api(tags = "流水号通配符规则表")
public class MdsCodeSequenceRegexController {

    @Autowired
    private MdsCodeSequenceRegexService mdsCodeSequenceRegexService;

    @ApiOperation(value = "查询流水号通配符规则表列表", httpMethod = "POST")
    @HibasePostRequestMapping(value = "selectMdsCodeSequenceRegexList")
    public ResponseModel<MdsCodeSequenceRegexListVO> selectMdsCodeSequenceRegexList(@RequestBody MdsCodeSequenceRegexSearchVO searchVO) {

        PageInfo result = mdsCodeSequenceRegexService.selectMdsCodeSequenceRegexList(searchVO);

        result.setList(EntityUtil.transform(result.getList(), MdsCodeSequenceRegexListVO.class));

        return ResponseModel.successMsg(result);
    }

    @ApiOperation(value = "新增流水号通配符规则表记录", httpMethod = "POST")
    @HibasePostRequestMapping(value = "insertMdsCodeSequenceRegex")
    public ResponseModel<String> insertMdsCodeSequenceRegex(@RequestBody MdsCodeSequenceRegexInsertVO insertVO) {

        MdsCodeSequenceRegex entity = EntityUtil.transform(insertVO, MdsCodeSequenceRegex.class);

        mdsCodeSequenceRegexService.saveMdsCodeSequenceRegex(entity);

        return ResponseModel.successMsg(entity.getId());
    }

    @ApiOperation(value = "修改流水号通配符规则表记录", httpMethod = "POST")
    @HibasePostRequestMapping(value = "updateMdsCodeSequenceRegex")
    public ResponseModel<String> updateMdsCodeSequenceRegex(@RequestBody MdsCodeSequenceRegexUpdateVO updateVO) {

        MdsCodeSequenceRegex entity = EntityUtil.transform(updateVO, MdsCodeSequenceRegex.class);

        mdsCodeSequenceRegexService.saveMdsCodeSequenceRegex(entity);

        return ResponseModel.successMsg(entity.getId());
    }

    @ApiOperation(value = "查询流水号通配符规则表详情", httpMethod = "POST")
    @HibasePostRequestMapping(value = "viewMdsCodeSequenceRegexDetails")
    public ResponseModel<MdsCodeSequenceRegexViewVO> viewMdsCodeSequenceRegexDetails(@RequestBody OperationIdEntity operationidEntity) {

        return ResponseModel.successMsg(EntityUtil.transform(mdsCodeSequenceRegexService.viewMdsCodeSequenceRegex(operationidEntity.getId()), MdsCodeSequenceRegexViewVO.class));
    }

    @ApiOperation(value = "删除流水号通配符规则表记录", httpMethod = "POST")
    @HibasePostRequestMapping(value = "/deleteMdsCodeSequenceRegex")
    public ResponseModel<String> deleteMdsCodeSequenceRegex(@RequestBody OperationIdEntity delete) {

        mdsCodeSequenceRegexService.deleteMdsCodeSequenceRegex(delete.getId());

        return ResponseModel.successMsg();
    }

    @ApiOperation(value = "刷新流水号", httpMethod = "POST")
    @HibasePostRequestMapping(value = "/refreshMdsCodeSequence")
    public ResponseModel<String> refreshMdsCodeSequence(@RequestBody MdsCodeSequenceRefreshVO refreshVO) {
        mdsCodeSequenceRegexService.refreshMdsCodeSequence(refreshVO);
        return ResponseModel.successMsg();
    }
}
